package com.link2room.optimus.controller.inside;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.link2room.common.constant.BaseConstant;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.optimus.dto.param.base.PriceStaticBaseParamDto;
import com.link2room.optimus.dto.result.base.PriceDto;
import com.link2room.optimus.facade.IStaticPriceFacadeService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by sss on 2016/8/29.
 */
@Api(tags = "基价管理")
@RestController
@RequestMapping("/in/StaticPrices")
public class StaticPriceInsideController {
    @Resource
    private IStaticPriceFacadeService staticPriceFacadeService;

    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto basePriceStatics(
            @RequestParam(value = "lhotelCode" ,required = true) String lhotelCode,
            @RequestParam(value = "priceCode" ,required = true) String priceCode,
            @RequestParam(value = "rmtype" ,required = false) String rmtype,
            @RequestParam(value = "startDatetime" ,required = false) String startDatetime,
            @RequestParam(value = "endDatetime" ,required = false) String endDatetime
    ) throws Exception {
        PriceStaticBaseParamDto priceStaticBaseParamDto =new PriceStaticBaseParamDto();
        priceStaticBaseParamDto.setLhotelCode(lhotelCode);
        priceStaticBaseParamDto.setStartDatetime(startDatetime);
        priceStaticBaseParamDto.setEndDatetime(endDatetime);
        priceStaticBaseParamDto.setPriceCode(priceCode);
        priceStaticBaseParamDto.setRmtype(rmtype);
        List<PriceDto> priceList = staticPriceFacadeService.listPriceStaticDto(priceStaticBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setListToQueryResult(priceList);
        return l2rRs;
    }

    @RequestMapping(method = RequestMethod.POST)
    public BaseResultDto newBasePriceStatics(
            @RequestBody PriceStaticBaseParamDto priceStaticBaseParamDto
    ) throws Exception {
        PriceDto priceDto=staticPriceFacadeService.saveOrUpdateStaticPrice(priceStaticBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(priceDto);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        return l2rRs;
    }

    @RequestMapping(method = RequestMethod.PUT)
    public BaseResultDto updateBasePriceStatics(
            @RequestBody PriceStaticBaseParamDto priceStaticBaseParamDto
    ) throws Exception {
        PriceDto priceDto=staticPriceFacadeService.saveOrUpdateStaticPrice(priceStaticBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(priceDto);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.UPDATESUCCESS);
        return l2rRs;
    }

    @RequestMapping(value = "/StaticPrice",method = RequestMethod.PUT)
    public BaseResultDto updateBasePriceStatic(
            @RequestBody PriceStaticBaseParamDto priceStaticBaseParamDto
    ) throws Exception {
        staticPriceFacadeService.updateStaticPrice(priceStaticBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.UPDATESUCCESS);
        return l2rRs;
    }

    @RequestMapping(value = "/StaticDayPriceIncrement",method = RequestMethod.PUT)
    public BaseResultDto updateDayPriceStaticIncrement(
            @RequestBody PriceStaticBaseParamDto priceStaticBaseParamDto
    ) throws Exception {
        staticPriceFacadeService.updateStaticDayPriceIncrement(priceStaticBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.UPDATESUCCESS);
        return l2rRs;
    }

    @RequestMapping(method = RequestMethod.DELETE)
    public BaseResultDto deleteBasePriceStatics(

    ) throws Exception {
        ObjectMapper objectMapper=new ObjectMapper();
        PriceStaticBaseParamDto priceStaticBaseParamDto =new PriceStaticBaseParamDto();
        staticPriceFacadeService.deletePriceStaticDayBatch(priceStaticBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.DELETESUCCESS);
        return l2rRs;
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public BaseResultDto deleteBasePriceStatics(
            @PathVariable Long id
    ) throws Exception {
        PriceStaticBaseParamDto priceStaticBaseParamDto =new PriceStaticBaseParamDto();
        priceStaticBaseParamDto.setId(id);
        staticPriceFacadeService.deletePriceStaticDay(priceStaticBaseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.DELETESUCCESS);
        return l2rRs;
    }
}
